﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace MEMDB
{
    public partial class Startup : Form
    {
        // The ip 
        private IPAddress ipAddress;
        private string userName;
        private string pwd;
        private int port;
        private bool pass = false;
        private String connectString;
        public void setMessage(String msg)
        {
            this.label4.Text = msg;
        }
        public int getPort()
        {
            return port;
        }
        public IPAddress getIp()
        {
            return ipAddress;
        }

        public string getUserName()
        {
            return userName;
        }

        public string getPwd()
        {
            return pwd;
        }

  

        public bool isPassed()
        {
            return pass;
        }

        public Startup()
        {
            InitializeComponent();
          //  this.tbIp.Text = "192.168.1.105";
            this.tbIp.Text = "127.0.0.1";
            this.tbPort.Text = "8888";
            this.tbUser.Text = "sse";
            this.tbPwd.Text = "sse";
         
        }

        // Login
        private void button1_Click(object sender, EventArgs e)
        {
            connectString = "";
            
            // get the ip address
            string strIp = tbIp.Text.Trim();
            if (!IPAddress.TryParse(strIp, out ipAddress))
            {
                MessageBox.Show("无效 IP.");
                return;
            }
            try
            {
                port = Convert.ToInt32(tbPort.Text.Trim());
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("无效端口号。" + ex.Message);
                return;
            }
            // 
            userName = tbUser.Text.Trim();
            if (userName.Length < 1)
            {
                MessageBox.Show("请输入您用户名.");
                return;
            }
            pwd = tbPwd.Text.Trim();
            if (pwd.Length < 1)
            {
                MessageBox.Show("请输入您的密码.");
                return;
            }
         
            pass = true;
           // login as sse sse
            connectString = "login as " + userName + " " + pwd + ";";
            this.Close();
        }

        public string getConnString()
        {
            return connectString;
        }
        // Exit 
        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认退出？", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                System.Environment.Exit(0);
            }
        }

        private void Startup_Load(object sender, EventArgs e)
        {

        }

      

    }
}
